<?
    session_start();
    include('conn.php');
    include('protect.php');
	include('gettopmenu.php');
   	error_reporting(0);

	$dt=date("d-m-Y");
    $dt1=date("d-m-Y");
	$msg='';
        
	if($_REQUEST['submit']=='Save Record')
	{
		$date=$_REQUEST['datepicker3'];
		$day= substr($date,0,2);
		$month = substr($date,3,2);
		$year = substr($date,6,4);
		$trndate=$year.'-'.$month.'-'.$day;
	
    	$paydate=$_REQUEST['paydate'];
		if (strlen($paydate)<>0)
		{
		$day= substr($paydate,0,2);
		$month = substr($paydate,3,2);
		$year = substr($paydate,6,4);
		$paydate=$year.'-'.$month.'-'.$day;
		}
		else
		{
			$paydate = '';
			//echo $paydate;
		}
		
//		$trndate=$_REQUEST['datepicker3'];
		
		$bid=$_REQUEST['bid'];
		$catid=$_REQUEST['catid'];
		$custid=$_REQUEST['custid'];
		$subid=$_REQUEST['sid'];
        $venid=$_REQUEST['venid'];
		$debitamt=$_REQUEST['dramount'];
		$creditamt=$_REQUEST['cramount'];
        $netrate=$_REQUEST['netrate'];
//		$balamt=$_REQUEST['balamount'];
		$remarks=$_REQUEST['remarks'];
		$payid=$_REQUEST['payid'];
		$bankid=$_REQUEST['bankid'];
		$branchname=$_REQUEST['branch'];
//		$paydate=$_REQUEST['paydate'];
		$payamt=$_REQUEST['amount'];
		$enteredby=$_SESSION['username'];
		$custid=str_replace('c',"",$custid);
		$custid=str_replace('d',"",$custid);
		$custid=str_replace('i',"",$custid);
		$custid=str_replace('r',"",$custid);
        $custid=str_replace('v',"",$custid);
		$idnumber=$_REQUEST['idnumber'];
		// if ($payid==1)
            // echo $payid;
            // alert($bankid);
		 if ($bankid==0)
		 $bankid=1;
		 if($payid==0)
		 $payid=8;

		 if($_SESSION["usertype"]==1)
		 {
			$status=0;
		 }
		 else
		 {
			$status=-1;
		 }
		 
		if ($subid==0)
			$subid=1;	
		$sql="insert into transactionmast(trndate,bid,catid,custid,subid,venid,debitamt,creditamt,netrate,remarks,payid,bankid,branchname,paydate,payamt,enteredby,entrydt,status,idnumber)
			values('".$trndate."','".$bid."','".$catid."','".$custid."','".$subid."','".$venid."','".$debitamt."','".$creditamt."','".$netrate."','".$remarks."','".$payid."','".$bankid."','".$branchname."','".$paydate."','".$payamt."','".$enteredby."',sysdate(),".$status.",'".$idnumber."')";
		$res=mysql_query($sql);
		//echo $sql;
		if($res)
		{
		?>	
           <script>window.location.href = 'transaction.php'</script>;		
        <? 			
		}
		else
		{
			$msg='Record not saved successfully';			
		}
	}
	

?>
 <script type="text/javascript" src="main.js"></script>
 <script language="javascript">
       $(function() {
               $("#datepicker3").datepicker({ dateFormat: "dd-mm-yy" }).val();
               $("#paydate").datepicker({ dateFormat: "dd-mm-yy" }).val();			   
       });
	  function chkamt()
	  {
	  	document.frmtran.balamount.value=document.frmtran.dramount.value-document.frmtran.cramount.value;
	  } 
	
	
	 function chknetbuyamt()
	  { 
	  document.getElementById('netrate').disabled = true;
	  var a=document.frmtran.venid.value;
		  if	(a == 0) 
	   {
	 //  alert(" value is"+document.frmtran.venid.value)
			document.getElementById('netrate').disabled = true;
			
	   }
	   else
	   {
	   //   alert(" value in else"+document.frmtran.venid.value)
	  	document.getElementById('netrate').disabled = false;
		} 
		
			/* var a=document.frmtran.custid.value;
			alert(" value is"+document.frmtran.custid.value);
			if(a.substring(0,1)=="v")
			{
			{
    		document.frmtran.netrate.disabled = true;
			}
			else
			{
			document.frmtran.netrate.disabled = true;
			}
			} */
		//var b=document.frmtran.venid.value;
		//alert(" value is"+document.frmtran.venid.value);
		
		/* if(b == 0)
		{
			document.frmtran.netrate.disabled = true;
		}
		else
		{
			document.frmtran.netrate.disabled = false;
		} */
		
	  } 
	
 //   function chkpay()
  //    {
//		if (document.frmtran.payid.value==2)
//		{
//			document.getElementById('bankid').disabled = false;
//			document.getElementById('branch').disabled = false;
//		}
//		else
//		{
//			document.getElementById('bankid').disabled = true;
//			document.getElementById('branch').disabled = true;
//		}
//	  }

    function chkdramt()
      {
    	if (document.frmtran.dramount.value>0)
		{
			document.getElementById('bankid').disabled = true;
			document.getElementById('branch').disabled = true;
            document.getElementById('paydate').disabled = true;
            document.getElementById('payid').disabled = true;
		}
		else
		{
			document.getElementById('bankid').disabled = false;
			document.getElementById('branch').disabled = false;
            document.getElementById('paydate').disabled = false;
            document.getElementById('payid').disabled = false;
		}
	  }

 function chkcramt()
      {
        if (document.frmtran.cramount.value>0)
		{
			document.getElementById('bankid').disabled = false;
          	document.getElementById('branch').disabled = false;
            document.getElementById('paydate').disabled = false;
            document.getElementById('payid').disabled = false;
		}
		else
		{
			document.getElementById('bankid').disabled = true;
			document.getElementById('branch').disabled = true;
            document.getElementById('paydate').disabled = true;
            document.getElementById('payid').disabled = true;
		}
	  }


	  function validatefrm()
	  {
		if (document.frmtran.payid.value==2)
		{
			if (document.frmtran.bankid.value==1)
			{
				alert("select Bank name");
				document.frmtran.bankid.focus();
				return false;
			}	
			if (document.frmtran.paydate.value=="")
			{
				alert("select Pay Date");
				document.frmtran.paydate.focus();
				return false;
			}	
			if (document.frmtran.branch.value=="")
			{
				alert("Enter Branch Name");
				document.frmtran.branch.focus();
				return false;
			}	
		}	
	  }
	function chgd()
	{
	  	//alert(document.frmtran.custid.value);
		var a=document.frmtran.custid.value;
		if(a.substring(0,1)=="i")
		{
			document.frmtran.sid.disabled = false;
		}
		else
		{
			document.frmtran.sid.disabled = true;
		}
		
              
        if(a.substring(0,1)=="c")
		{
			document.getElementById('ct').innerHTML="Customer";
		}
		if(a.substring(0,1)=="i")
		{
			document.getElementById('ct').innerHTML="Distributor";
		}
		if(a.substring(0,1)=="d")
		{
			document.getElementById('ct').innerHTML="Agent";
		}
         if(a.substring(0,1)=="r")
        {
			document.getElementById('ct').innerHTML="Corporate";
		}
        if(a.substring(0,1)=="v")
        {
    		document.getElementById('ct').innerHTML="Vendor";
		}
	}  
 </script>
 
 
 
<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Transaction / Add Transaction</label></td>
<div  align="center">
	<div  ng-controller="MyCtrl">
	<div align="center">
			<FORM METHOD="post" name="frmtran" action="transaction.php" onsubmit="return validatefrm();">
			<table  cellpadding="4" id="box-table-a" cellspacing="4" border="1" width="874" bgcolor="#000000" style="background-color:#DFEBF9;">
				<tr><td colspan="6" align="center" height="30" style="text-align:center; color:#FF0000;"><?=$msg?></td></tr>
				<tr><td colspan="6" align="center" height="30" style="text-align:center;font-size:14px; color:#333333; font-weight:bold; ">Transaction Master</td></tr>
				<tr bgcolor="#FFFFFF">
				  <td width="149"><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Date</label></td>
				  <td width="9"><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="272" style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= "" value="<?=$dt?>" id="datepicker3" name="datepicker3" class="smallInput" />				  </td>
				  <td colspan="3"><div id="ct" style="color:#669900; border:thin" ></label></td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Nature Of Business</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="bid" id="bid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							$sqlb="select * from businessmast where status=0 order by bdesc";
							$resb=mysql_query($sqlb);
							while($rowb=mysql_fetch_assoc($resb))
							{
						?>
							<option value="<?=$rowb['bid']?>"><?=$rowb['bdesc']?></option>
						<?
							}
						?>	
						</select>					</td>
				  <td width="99" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Sub Category</label></td>
				  <td width="5" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="250"  style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="catid" id="catid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							$sqlc="select * from categorymast where status=0 order by catdesc";
							$resc=mysql_query($sqlc);
							while($rowc=mysql_fetch_assoc($resc))
							{
						?>
							<option value="<?=$rowc['catid']?>"><?=$rowc['catdesc']?></option>
						<?
							}
						?>	
						</select>				  </td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Customer Name</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<p>
						  <select  name="custid" id="custid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" onchange="chgd();">
						    <?
							$sqlct="select * from customermast where status=0 and custtype != 'VENDOR' order by custdesc";
							$resct=mysql_query($sqlct);
							while($rowct=mysql_fetch_assoc($resct))
							{
							if($rowct['custtype']=='AGENT')
								$cid='d'.$rowct['custid'];
							if($rowct['custtype']=='CUSTOMER')
								$cid='c'.$rowct['custid'];
							if($rowct['custtype']=='DISTRIBUTOR')
								$cid='i'.$rowct['custid'];
                            if($rowct['custtype']=='CORPORATE')
    							$cid='r'.$rowct['custid'];
                            if($rowct['custtype']=='VENDOR')
        						$cid='v'.$rowct['custid'];
							//else
								//$cid='c'.$rowct['custid'];
							
							?>
						    <option value="<?=$cid?>">
					        <?=$rowct['custdesc']?>
					        </option>
					        <?
							}
						?>	
					      </select>
					  </p>
					<p>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Sub-Agent Name </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="sid" id="sid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							$sqlcts="select * from subdealermast where status=0 order by subname";
							$rescts=mysql_query($sqlcts);
							while($rowcts=mysql_fetch_assoc($rescts))
							{
						?>
							<option value="<?=$rowcts['subid']?>"><?=$rowcts['subname']?></option>
						<?
							}
						?>	
						</select>					</td>
				</tr>
                
                    <tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">From Vendor </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="venid" id="venid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" onchange="chknetbuyamt();" >
						<option value="0">--</option>
						<?
							$sqlb="select * from customermast where status=0 and custtype = 'VENDOR' order by custdesc";
							$resb=mysql_query($sqlb);
							while($rowb=mysql_fetch_assoc($resb))
							{
						?>
							<option value="<?=$rowb['custid']?>"><?=$rowb['custdesc']?></option>
						<?
							}
						?>	
						</select>					</td>
				 <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Net Buy Rate</label></td>
    				<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input name="netrate" type="text"  class="smallInput" disabled  id="netrate" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" value="0" onchange="chknetbuyamt();"  placeholder="00" />					</td>
				
				</tr>
                
                
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Dr. Amount</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input name="dramount" type="text" class="smallInput" onblur="chkdramt();" id="dramount" style="width:80px; text-align:right; font-size:12px; font-weight:bold;" value="0"  required= "" placeholder="00" />					</td>
				
                <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Cr. Amount</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input name="cramount" type="text"  class="smallInput" onblur="chkcramt();"  id="cramount" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" value="0" required= "" placeholder="00" />					</td>
				</tr>
<!--				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Balance</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="balamount" name="balamount" class="smallInput" required= "" disabled="disabled" placeholder="00" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" />					
					</td>
				</tr>
-->				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Remarks</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					 <textarea name="remarks" cols="45" rows="2" class="smallInput" id="remarks" style="font-size:12px; text-align:left; font-weight:bold;"></textarea>					</td>
					
					    <td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">ID Number</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
				    <input name="idnumber" type="text" class="smallInput"  id="idnumber"  placeholder="Id Number" style="width:245px; font-size:12px; font-weight:bold;"  onchange="chgd();" /></td> 
					
				</tr>
				<tr bgcolor="#FFFFFF">
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Payment Mode</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;"><select  name="payid" id="payid" class="smallInput" onchange="chkpay();" style="width:150px; font-size:12px; font-weight:bold;" >
                      <?
							$sqlcp="select * from paymentmast where status=0 order by pdesc";
							$rescp=mysql_query($sqlcp);
							while($rowcp=mysql_fetch_assoc($rescp))
							{
						?>
                      <option value="<?=$rowcp['payid']?>">
                        <?=$rowcp['pdesc']?>
                      </option>
                      <?
							}
						?>
                    </select></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Pay Date</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="paydate"  value="<?=$dt1?>" name="paydate" class="smallInput" />					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Bank Name</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="bankid" id="bankid" class="smallInput" style="width:150px; font-size:12px; font-weight:bold;" >
						<?
							$sqlck="select * from bankmast where status=0 order by bankname";
							$resck=mysql_query($sqlck);
							while($rowck=mysql_fetch_assoc($resck))
							{
						?>
							<option value="<?=$rowck['bankid']?>"><?=$rowck['bankname']?></option>
						<?
							}
						?>	
						</select>					</td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Branch</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="branch" name="branch" class="smallInput"   placeholder="Branch" style="width:245px; font-size:12px; font-weight:bold;" />					</td>
				</tr>
				<tr>
					<td align="center" colspan="6" style="background-color:#BBE2EE">
						<input type="submit"  name="submit" value="Save Record" />					</td>
				</tr>
			</table>
			</FORM>
	
	</div>

<!--		OR
		</br>
		<strong>Reference No:</strong> </string>
		<input type="text" ng-model="Referenceno"/>	</br>      
		<button ng-click="activateFilter()"> Search </button>   <br/>
			<br/>
-->
</div>
</div>
</body>
</html>
